<template>
    <div class="contain-box">
        <div class="box-header">
            <el-breadcrumb separator="/">
                <el-breadcrumb-item>物流管理</el-breadcrumb-item>
                <el-breadcrumb-item to="/logisticsChannels" replace>物流渠道</el-breadcrumb-item>
                <el-breadcrumb-item>编辑渠道</el-breadcrumb-item>
            </el-breadcrumb>
        </div>

        <div class="box-body">
            <div class="box-nav">基础信息</div>
            <div class="body-set">
                <el-input v-model="editObj.channelName" placeholder="渠道名称" style="width: 300px;margin-right: 10px"
                          size="small"></el-input>
                <el-input v-model="editObj.queryWebsite" placeholder="查询网址" style="width: 300px;margin-right: 10px;"
                          size="small"></el-input>
                是否启用：
                <el-switch
                        v-model="editObj.status"
                        active-value="1"
                        inactive-value="0"
                        active-color="#1abc9c"
                >
                </el-switch>
            </div>
            <div class="box-nav" style="margin-top: 20px">报价规则</div>
            <div class="body-set">
                计费类型：
                <el-select v-model="editObj.chargeType" placeholder="请选择计费类型" size="small"
                           style="width: 300px;margin-right: 10px">
                    <el-option v-for="item in importExport" :key="item.id" :label="item.name"
                               :value="item.id"></el-option>
                </el-select>

                <div v-show="editObj.chargeType">
                    {{editObj.chargeType===2?'单价/㎡':editObj.chargeType===1?'单价/kg':'单价/件'}}：
                    <el-input v-model="editObj.numericalNum" placeholder="请输入单价" size="small"
                              style="width: 300px;margin-right: 10px"></el-input>
                </div>

            </div>
        </div>
        <div class="box-submit">
            <div class="submit-left">
            </div>
            <div>
                <el-button @click="goBack" size="small">取 消</el-button>
                <el-button @click="submitEdit" type="primary" size="small" style="background-color: #1abc9c">保存并编辑
                </el-button>
            </div>
        </div>
    </div>
</template>

<script>
    export default {
        data() {
            return {
                importExport: [
                    {
                        id: 1,
                        name: '重量计费'
                    },
                    {
                        id: 2,
                        name: '体积计费'
                    },
                    {
                        id: 3,
                        name: '按件计费'
                    }
                ],
                editObj: {}
            }

        },
        created() {
            this.findById(this.$route.query.id)
        },
        methods: {
            findById(id) {
                this.axios.get('/logisticsChannel/findById?id=' + id).then(res => {
                    if (res.data.code === 200) {
                        this.editObj = res.data.data
                        this.editObj.status = this.editObj.status + ''
                    }
                })
            },
            goBack() {
                this.$router.go(-1)
            },
            submitEdit() {
                this.axios.post('/logisticsChannel/edit', this.editObj).then(res => {
                    if (res.data.code === 200) {
                        this.goBack()
                        this.$message.success('编辑成功')
                    }
                })
            }
        }
    }
</script>

<style scoped lang="less">
    .contain-box {
        width: 100%;
        height: 100%;

        .box-header {
            width: 100%;
            height: 50px;
            display: flex;
            align-items: center;
            margin-bottom: 10px;
        }

        .box-body {
            width: 100%;
            border-radius: 5px;
            padding: 20px;
            box-sizing: border-box;
            box-shadow: 0 0 5px 0 #e4e4e4;

            .box-nav {
                width: 100%;
                height: 40px;
                line-height: 40px;
                padding-left: 10px;
                box-sizing: border-box;
                font-size: 14px;
                color: #666;
                border-left: 5px solid #1abc9c;
                background-color: #f9f9f9;
            }

            .body-top {
                width: 100%;
                height: 50px;
                text-align: center;
                line-height: 50px;
                border-bottom: 1px solid #e4e4e4;
                font-size: 20px;
                color: #666;
            }

            .body-set {
                margin-top: 20px;
                width: 100%;
                display: flex;
                align-items: center;
                justify-content: flex-start;
            }

            .body-add {
                margin-top: 20px;
                width: 100%;
            }

            .body-table {
                margin-top: 20px;
                width: 100%;
            }

            .body-message {
                margin-top: 20px;
                width: 100%;

                .message-box {
                    margin-top: 20px;
                    display: flex;
                    align-items: center;
                    cursor: pointer;

                    .message-img {
                        margin-left: 20px;
                        width: 20px;
                        height: 20px;
                    }

                    .message-son {
                        margin-right: 15px;
                        font-size: 14px;
                    }
                }
            }
        }

        .box-submit {
            margin-top: 20px;
            width: 100%;
            border-radius: 5px;
            padding: 20px;
            box-sizing: border-box;
            display: flex;
            align-items: center;
            justify-content: space-between;
            box-shadow: 0 0 5px 0 #e4e4e4;

            .submit-left {
                display: flex;
                font-size: 16px;

                p {
                    margin-right: 20px;

                    span {
                        color: red;
                        font-weight: bold;
                    }
                }
            }
        }
    }
</style>
